import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/* Router Modules */
import componentsRouter from './modules/components'
import chartsRouter from './modules/charts'
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'
export const constantRouterMap = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: '首页',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
      }
    ]
  }
  // {
  //   path: '/task',
  //   component: Layout,
  //   redirect: '/task/releaseList',
  //   name: 'task',
  //   meta: {
  //     title: '任务',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/task/create'),
  //       name: 'create',
  //       meta: { title: '创建任务', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/task/edit'),
  //       name: 'edit',
  //       meta: { title: 'editArticle', noCache: true },
  //       hidden: true
  //     },
  //     {
  //       path: 'releaseList',
  //       component: () => import('@/views/task/releaseList'),
  //       name: 'releaseList',
  //       meta: { title: '我发布的任务', icon: 'list', role: ['editor'] }
  //     },
  //     {
  //       path: 'receiveList',
  //       component: () => import('@/views/task/receiveList'),
  //       name: 'receiveList',
  //       meta: { title: '未领取任务', icon: 'list' }
  //     },
  //     {
  //       path: 'handleList',
  //       component: () => import('@/views/task/handleList'),
  //       name: 'handleList',
  //       meta: { title: '已领取任务列表', icon: 'list' }
  //     }
  //   ]
  // }
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/list',
  //   name: 'Example',
  //   meta: {
  //     title: 'example',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/example/create'),
  //       name: 'CreateArticle',
  //       meta: { title: 'createArticle', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/example/edit'),
  //       name: 'EditArticle',
  //       meta: { title: 'editArticle', noCache: true },
  //       hidden: true
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/example/list'),
  //       name: 'ArticleList',
  //       meta: { title: 'articleList', icon: 'list' }
  //     }
  //   ]
  // },
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   redirect: '/documentation/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/documentation/index'),
  //       name: 'Documentation',
  //       meta: { title: 'documentation', icon: 'documentation', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/guide',
  //   component: Layout,
  //   redirect: '/guide/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/guide/index'),
  //       name: 'Guide',
  //       meta: { title: 'guide', icon: 'guide', noCache: true }
  //     }
  //   ]
  // }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/task',
    component: Layout,
    alwaysShow: true, // will always show the root menu
    meta: {
      title: 'permission',
      icon: 'example',
      roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'create',
        component: () => import('@/views/task/create'),
        name: 'createTask',
        meta: {
          title: '创建任务',
          name: 'createTask',
          icon: 'form',
          roles: ['editor', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'edit/:id(\\d+)',
        component: () => import('@/views/task/edit'),
        name: 'editTask',
        meta: {
          title: '创建任务',
          name: 'createTask',
          icon: 'edit',
          roles: ['editor', 'admin'] // or you can only set roles in sub nav
        },
        hidden: true
      },
      {
        path: 'releaseList',
        component: () => import('@/views/task/releaseList'),
        name: 'releaseList',
        meta: {
          title: '我发布的任务',
          name: 'releaseList',
          icon: 'list',
          roles: ['editor', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'receiveList',
        component: () => import('@/views/task/receiveList'),
        name: 'receiveList',
        meta: {
          title: '未领取任务',
          name: 'receiveList',
          icon: 'nested',
          roles: ['editor', 'admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'handleList',
        component: () => import('@/views/task/handleList'),
        name: 'handleList',
        meta: {
          title: '已领取任务列表',
          name: 'handleList',
          icon: 'component',
          roles: ['editor', 'admin'] // or you can only set roles in sub nav
        }
      }
    ]
  },
  {
    path: '/icon',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/svg-icons/index'),
        name: 'Icons',
        meta: { title: 'icons', icon: 'icon', noCache: true }
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    redirect: 'noredirect',
    name: 'ErrorPages',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    children: [
      {
        path: '401',
        component: () => import('@/views/errorPage/401'),
        name: 'Page401',
        meta: { title: 'page401', noCache: true }
      },
      {
        path: '404',
        component: () => import('@/views/errorPage/404'),
        name: 'Page404',
        meta: { title: 'page404', noCache: true }
      }
    ]
  },
  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://github.com/PanJiaChen/vue-element-admin',
  //       meta: { title: 'externalLink', icon: 'link' }
  //     }
  //   ]
  // },

  { path: '*', redirect: '/404', hidden: true }
]
